#define D(s) s=p[e++]-48;while(p[e]!=58&&p[e])s=10*s+p[e++]-48;e++;
void main(int n,char**a){char t[30],*p=*a,c,e=0,h,m,i=0;gets(p);D(c)while(i<c){gets(p);e=0;D(h)D(m)m>0?t[i]=0:(t[i]=h+12,t[i]>24?t[i]%=24:0);i++;}i=0;while(i<c-1){printf("%d\n",t[i++]);}printf("%d",t[i]);}